var t = getApp(),
  a = t.requirejs("core"),
  s = t.requirejs("wxParse/wxParse");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    countDownDay: 0,
    countDownHour: 0,
    countDownMinute: 0,
    countDownSecond: 0,
    show_time: true,
    advWidth:750,
    icons: t.requirejs("icons")
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    this.setData(options)
    this.detail()
    wx.getSystemInfo({//获取系统资料
      success: function (t) {
        console.log(t)
        that.setData({
          advWidth: t.windowWidth  //窗口宽度
        })
      }
    })
  },
  /**
   * 商品详情
   */
  detail: function () {
    var that = this,
      id = that.data.id;
    a.get('Miaosha/msGoodsDetail',{
      id:id
    },function(t){
      console.log(t)
      if(t.code==0){
        that.setData({
          info:t.info
        })
        wx.setNavigationBarTitle({
          title: t.info.name || "活动详情"
        })
        if (t.info.description) {
          s.wxParse("wxParseData", "html", t.info.description, that, "0");
        }
        //倒计时
        if (t.info.status>0){
          if (t.info.status == 2) {
            var time = t.info.etime;
          } else if (t.info.status == 1) {
            var time = t.info.stime;
          }
          a.Countdown(time, function (i) {
            that.setData(i)
          })
        }
        
       
      }else{
        a.alert(t.msg,function(){
          return;
        });

      }
    },true);
    
  },
  

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.detail();
    wx.stopPullDownRefresh();
  },
  /**
   * 跳转至地图
   */
  navigate: function () {
    var that = this;
    var t = this.data.about_info;
    if (t.name && t.lat && t.lng) {
      a.tx_map(t.lat, t.lng, t.name)
    } else {
      a.toast('获取位置失败')
    }
  },

  /**
   * 直接购
   */
  shoping: function (e) {
    var that = this,
      data = a.pdata(e);
    if (!that.data.show_time) {
      a.alert('该活动已经结束')
      return false;
    }
    if (that.data.info.rest_sell < 1) {
      a.alert('库存不足')
      return false;
    }
    wx.navigateTo({
      url: "/yb_shop/pages/miaosha/order/create/index?bargain_id=" + that.data.info.id + "&total=1&uid=" + getApp().getCache("userinfo").uid + "&activity_order_type=3&current_price=" + that.data.info.nprice + '&pic=' + that.data.info.pic + '&name=' + that.data.info.name + '&goods_id=' + that.data.info.goods_id
    })
  },
  /**
   * 打电话
   */
  phone: function (e) {
    a.phone(e)
  },
  /**
     * 用户点击右上角分享
     */
  onShareAppMessage: function () {
    var title = this.data.info.name;
    var path = '/yb_shop/pages/miaosha/seckillGoods/index?id=' + this.data.info.id;
    return {
      title: title,
      path: path
    }
  }
})